import {Component, OnInit} from '@angular/core';
import 'handsontable/languages/zh-CN.js';
import SheetClip from 'handsontable/lib/SheetClip/SheetClip';

@Component({
  selector: 'app-import',
  templateUrl: './import.component.html',
  styleUrls: ['./import.component.css']
})
export class ImportComponent implements OnInit {
  clipboardCache = '';

  contextMenu = [
    'undo',
    'redo',
    '---------',
    'cut',
    'copy',
    {
      key: 'paste',
      name: '粘贴',
      disabled() {
        return !this.clipboardCache;
      },
      callback() {
        const plugin = this.getPlugin('copyPaste');

        this.listen();
        plugin.paste(this.clipboardCache);
      }
    },
    '---------',
    'row_above',
    'row_below',
    'remove_row',
    'clear_column',
    '---------',
    'alignment'
  ];

  dataSet: any[] = [
    {id: 1, name: 'Ted Right', sex: '男', age: 33, address: 'Wall Street', birthday: '1999-09-19'},
    {id: 2, name: 'Frank Honest', sex: '女', age: 33, address: 'Pennsylvania Avenue', birthday: '1999-09-19'},
    {id: 3, name: 'Joan Well', sex: '男', age: 33, address: 'Broadway', birthday: '1999-09-19'},
    {id: 4, name: 'Gail Polite', sex: '男', age: 33, address: 'Bourbon Street', birthday: '1999-09-19'},
  ];

  constructor() {
  }

  ngOnInit(): void {
  }

  afterCopy(event, data) {
    event.clipboardCache = SheetClip.stringify(data);
  }

  afterCut(event, data) {
    event.clipboardCache = SheetClip.stringify(data);
  }

  afterPaste(event, data) {
    event.clipboardCache = SheetClip.stringify(data);
  }

  ageValidator(value, callback) {
    callback(false);
  }
}
